﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;

namespace NthDownload.Converters
{
    public class BooleanToVisiblityConverter : IValueConverter
    {
        #region Properties

        public Visibility TrueValue { get; set; }
        public Visibility FalseValue { get; set; }

        #endregion Properties

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return Binding.DoNothing;

            bool boolValue = System.Convert.ToBoolean(value);

            return (boolValue) ? TrueValue : FalseValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Visibility? visibilityValue = value as Visibility?;

            if (!visibilityValue.HasValue) return Binding.DoNothing;

            if (visibilityValue.Value == TrueValue)
            {
                return true;
            }
            
            if (visibilityValue.Value == FalseValue)
            {
                return false;
            }

            return Binding.DoNothing;
        }
    }
}
